package cn.nfwx.tv.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.List;

import static cn.nfwx.tv.adapter.NyqfNewAdapter.ITEM_IMG;
import static cn.nfwx.tv.adapter.NyqfNewAdapter.ITEM_TEXT;
import static cn.nfwx.tv.adapter.NyqfNewAdapter.ITEM_VIDEO;

public final class NyqfBean implements Parcelable {

    private List<NewBean> news;
    private List<NavBean> nav;

    public NyqfBean() {

    }

    protected NyqfBean(Parcel in) {
        news = in.createTypedArrayList(NewBean.CREATOR);
        nav = in.createTypedArrayList(NavBean.CREATOR);
    }

    public static final Creator<NyqfBean> CREATOR = new Creator<NyqfBean>() {
        @Override
        public NyqfBean createFromParcel(Parcel in) {
            return new NyqfBean(in);
        }

        @Override
        public NyqfBean[] newArray(int size) {
            return new NyqfBean[size];
        }
    };

    public List<NewBean> getNews() {
        return news;
    }

    public void setNews(List<NewBean> news) {
        this.news = news;
    }

    public List<NavBean> getNav() {
        return nav;
    }

    public void setNav(List<NavBean> nav) {
        this.nav = nav;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeTypedList(news);
        dest.writeTypedList(nav);
    }

    public final static class NewBean implements Parcelable, MultiItemEntity {
        /**
         * title : 【学习在线】始终坚持以人民为中心的发展思想，总书记这样说
         * poster :
         * nav : zhyw
         * time : 2018-11-26
         * id : 66755
         */

        private String title;
        private String poster;
        private String nav;
        private String time;
        private String id;

        public NewBean() {

        }

        protected NewBean(Parcel in) {
            title = in.readString();
            poster = in.readString();
            nav = in.readString();
            time = in.readString();
            id = in.readString();
        }

        public static final Creator<NewBean> CREATOR = new Creator<NewBean>() {
            @Override
            public NewBean createFromParcel(Parcel in) {
                return new NewBean(in);
            }

            @Override
            public NewBean[] newArray(int size) {
                return new NewBean[size];
            }
        };

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getPoster() {
            return poster;
        }

        public void setPoster(String poster) {
            this.poster = poster;
        }

        public String getNav() {
            return nav;
        }

        public void setNav(String nav) {
            this.nav = nav;
        }

        public String getTime() {
            return time;
        }

        public void setTime(String time) {
            this.time = time;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(title);
            dest.writeString(poster);
            dest.writeString(nav);
            dest.writeString(time);
            dest.writeString(id);
        }

        @Override
        public int getItemType() {
            if (TextUtils.isEmpty(poster)) {
                return ITEM_TEXT;
            }
            if (poster.contains(".mp4") || poster.contains(".flv")) {
                return ITEM_VIDEO;
            } else if (poster.contains(".jpg") || poster.contains(".png")) {
                return ITEM_IMG;
            } else {
                return ITEM_TEXT;
            }
        }
    }

    public final static class NavBean implements Parcelable {
        /**
         * code : lzgc
         * title : 廉政教育
         */

        private String code;
        private List<DataBean> data;


        protected NavBean(Parcel in) {
            code = in.readString();
            data = in.createTypedArrayList(DataBean.CREATOR);
        }

        public NavBean() {

        }

        public static final Creator<NavBean> CREATOR = new Creator<NavBean>() {
            @Override
            public NavBean createFromParcel(Parcel in) {
                return new NavBean(in);
            }

            @Override
            public NavBean[] newArray(int size) {
                return new NavBean[size];
            }
        };

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }


        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {

            dest.writeString(code);
            dest.writeTypedList(data);
        }

        public List<DataBean> getData() {
            return data;
        }

        public void setData(List<DataBean> data) {
            this.data = data;
        }
    }

    public final static class DataBean implements Parcelable {

        /**
         * code : lzgc
         * title : 廉政教育
         */

        private String code;
        private String title;

        protected DataBean(Parcel in) {
            code = in.readString();
            title = in.readString();
        }

        public DataBean() {

        }

        public DataBean(String code, String title) {
            this.code = code;
            this.title = title;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(code);
            dest.writeString(title);
        }

        @Override
        public int describeContents() {
            return 0;
        }

        public static final Creator<DataBean> CREATOR = new Creator<DataBean>() {
            @Override
            public DataBean createFromParcel(Parcel in) {
                return new DataBean(in);
            }

            @Override
            public DataBean[] newArray(int size) {
                return new DataBean[size];
            }
        };

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }
    }
}
